<template>
  <el-dialog
    ref="dialog"
    width="60%"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
  >
    <slot />
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="handleCancel">Cancel</el-button>
        <el-button
          type="primary"
          :loading="confirmLoading"
          @click="handleConfirm"
        >Confirm</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script lang="ts" setup>
import { ref } from 'vue';

const props = defineProps({
  confirm: {
    type: Function,
    default: () => Promise.resolve()
  }
})

// interface EmitType {
//   (e: 'confirm'): void
// }

// const emit = defineEmits<EmitType>()

const confirmLoading = ref(false)
const dialog = ref()

const handleCancel = () => {
  console.log(dialog.value)
  if (dialog.value) {
    dialog.value.visible = false
  }
}
const handleConfirm = async () => {
  confirmLoading.value = true
  props.confirm().finally(() => {
    confirmLoading.value = false
  })
}

</script>
